package com.yanfan.data.controller;

import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.iot.domain.Case;
import com.yanfan.iot.service.CaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "案例")
@RestController
@RequestMapping("/iot/case")
public class CaseController extends BaseController {

    @Autowired
    private CaseService caseService;

    @ApiOperation("查询案例列表")
    @GetMapping("/list")
    public TableDataInfo list(Case cases) {
        startPage();
        List<Case> list = caseService.selectAllCase(cases);
        return getDataTable(list);
    }

    @ApiOperation("案例新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Case cases) {
        int i = caseService.addCase(cases);
        if (i > 0) {
            return AjaxResult.success("新增成功");
        }
        return AjaxResult.error("新增失败");
    }

    @ApiOperation("案例修改")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Case cases) {
        int i = caseService.updateCase(cases);
        if (i > 0) {
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.error("修改失败");
    }

    @ApiOperation("案例修改")
    @GetMapping("/delete")
    public AjaxResult delete(Integer id) {
        int i = caseService.deleteCase(id);
        if (i > 0) {
            return AjaxResult.success("删除成功");
        }
        return AjaxResult.error("删除失败");
    }
}
